"""models"""

from dataclasses import dataclass
from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import DateTime
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column


@dataclass
class BaseModel(DeclarativeBase):
    """
    基类
    create_time: 创建时间
    update_time: 更新时间
    """

    create_time: Mapped[DateTime] = mapped_column(
        DateTime, nullable=False, default=datetime.now()
    )
    update_time: Mapped[DateTime] = mapped_column(
        DateTime, nullable=False, default=datetime.now, onupdate=datetime.now()
    )


db = SQLAlchemy(model_class=BaseModel)
